//
//  QZDownView.m
//  map
//
//  Created by 000 on 16/7/28.
//  Copyright © 2016年 faner. All rights reserved.
//

#import "QZDownView.h"

@interface QZDownView ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (nonatomic, assign) int i;

- (IBAction)determineBtnClick;
@end

@implementation QZDownView

+ (instancetype)downViewWithFrame:(CGRect)frame
{
    QZDownView *downView = [[NSBundle mainBundle] loadNibNamed:@"QZDownView" owner:nil options:nil].lastObject;
    downView.frame = frame;
    //设置背景颜色
    downView.backgroundColor = [UIColor whiteColor];
    return downView;
}

- (void)awakeFromNib
{
    self.i = 0;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
    [self addGestureRecognizer:tapGesture];
    
}
- (void)show
{
    //获取主Window
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    [keyWindow addSubview:self];
    self.alpha = 0.0f;
    [UIView animateWithDuration:0.3f animations:^{
        self.alpha = 1.0f;
    } completion:^(BOOL finished) {
        //弹出键盘
        [self.textView becomeFirstResponder];
    }];
}
- (void)hide
{
    [UIView animateWithDuration:0.3f animations:^{
        self.alpha = 0.0f;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (IBAction)determineBtnClick {
//    NSLog(@"%@",self.textView.text);
    self.i++;
    [self hide];
    if ([self.delegate respondsToSelector:@selector(downView:didDeterMineBtnClickWithText: andI:)]) {
        [self.delegate downView:self didDeterMineBtnClickWithText:self.textView.text andI:self.i];
    }
}

@end
